package com.rede.didiok.user.modulelist.rank.web;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.common.constant.conf.SysConf;
import com.rede.didiok.common.dto.rank.RankPraiseRecordDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.utils.R;
import com.rede.didiok.common.utils.ResultUtil;
import com.rede.didiok.common.validator.group.Insert;
import com.rede.didiok.user.modulelist.rank.entity.RankPraiseRecordEntity;
import com.rede.didiok.user.modulelist.rank.service.RankPraiseRecordService;


/**
 * 用户点赞表
 *
 * @author Rede
 * @email didiok@foxmail.com
 * @date 2023-09-05 17:47:48
 */
@Slf4j
@RestController
@RequestMapping("rank/feign/praiseRecord")
public class RankPraiseRecordController {
    @Autowired
    private RankPraiseRecordService rankPraiseRecordService;

    @ApiOperation(value = "获取点赞/踩数", notes = "点赞/踩数")
    @PostMapping("/getRankPraiseCount")
    public String getRankPraiseCount(@Validated({Insert.class}) @RequestBody RankPraiseRecordDto rankPraiseRecordDto, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("检查是否点赞");
        return ResultUtil.result(SysConf.SUCCESS, rankPraiseRecordService.getPraiseCount(rankPraiseRecordDto));
    }

    /**
     * 修改
     */
    @RequestMapping("/updateById")
    // @RequiresPermissions("rank:praiserecord:update")
    public R updatePraiseRecordById(@RequestBody RankPraiseRecordDto praiseRecordDto){
        RankPraiseRecordEntity praiseRecord = new RankPraiseRecordEntity();
        BeanUtils.copyProperties(praiseRecordDto, praiseRecord);
		rankPraiseRecordService.updateById(praiseRecord);

        return R.ok();
    }


}
